package com.wanwu.channel.controller;

import com.wanwu.channel.biz.ProfitSharingOrderService;
import com.wanwu.channel.controller.resp.ResponseObject;
import com.wanwu.channel.model.SettleReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 分账接口控制器
 */
@RestController
@Slf4j
@RequestMapping("/wxpay")
public class WXPaySettleController {


    @Resource
    private ProfitSharingOrderService profitSharingOrderService;

    /**
     * 设置分账接口
     */
    @PostMapping("/settle")
    @ResponseBody
    public ResponseObject settle(@RequestBody SettleReq req) throws Exception {
        ResponseObject responseObject = new ResponseObject();
        responseObject.setCode("10000");
        responseObject.setMessage("成功");
        try {
            // 调用分账接口实现分账逻辑
            profitSharingOrderService.insert(req);
            Map<String,String> info = new HashMap<>();
            info.put("settleNo",req.getOutTradeNo());//商户订单号
            info.put("tradeNo",req.getTransactionId());//微信交易号
            responseObject.setData(info);
        } catch (Exception e) {
            log.error("分账结算失败", e);
            responseObject.setCode("20001");
            responseObject.setMessage("参数错误");
        }
        return responseObject;
    }
}